﻿#define _CRT_SECURE_NO_WARNINGS 1

//455. 分发饼干
class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {

        // 先排序
        sort(g.begin(), g.end());
        sort(s.begin(), s.end());
        // 利⽤双指针找答案
        int ret = 0, m = g.size(), n = s.size();
        for (int i = 0, j = 0; i < m && j < n; ++i, ++j)
        {
            while (j < n && s[j] < g[i]) ++j;// 找饼⼲
            if (j < n) ret++;
        }
        return ret;
    }
};